package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.utils.FallbackMethod;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author yangjin
 * @Description
 * @Date 2021/6/27/14:40
 **/
@RestController
@DefaultProperties(defaultFallback = "paymentFeignTimeOut_toSlove")
public class OrderFeignController {

    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping(value = "/paymentByConsumer/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        return paymentFeignService.getPaymentById(id);
    }

    @GetMapping(value = "/consumer/payment/feign/timeout")
    /*@HystrixCommand(fallbackMethod = "paymentFeignTimeOut_toSlove"
            ,commandProperties = @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1000"))*/
    @HystrixCommand
    public String paymentFeignTimeOut(){
        return paymentFeignService.paymentFeignTimeOut();
    }

    private String paymentFeignTimeOut_toSlove(){
        return "服务【cloud-provider-payment8001】提供的方法睡眠3秒，此时消费者调用等待超过1秒就按超时处理，此信息为消费者fallback方法返回42gdfs sgsegsers";
    }


}
